#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include"QMessageBox"
#include"client.h"
#include"form3d.h"
#include"formcharts.h"
#include"QFileDialog"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    pool = new ThreadPool(4);
    serverStatus =  ui->serverStatus;
    onlineLbl=ui->onlineLbl;
    rcvText=ui->rcvText;

    serverStatus->setText("当前服务器状态: 停止");


    instance=this;
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_startBtn_clicked() {

    tcpServer = new MyTcpServer(instance    );
    serverStatus->setText("当前服务器状态: 启动");
    tcpServer->connectServer();
}


void MainWindow::on_stopButton_clicked() {
    serverStatus->setText("当前服务器状态: 停止");
    tcpServer->stopServer();
}


void MainWindow::on_pushButton_clicked()
{
    qDebug()<<"消息群发";
    tcpServer->massSend("massage message to everyone");
    //number_my->setText("当前服务器状态: 111111止");


}

void MainWindow::print_test(std::string message){
 //QMessageBox::information(this,"ss",QString::fromStdString(message),"");
    onlineLbl->setText(QString::fromStdString(message));

}



void MainWindow::on_startClientBtn_clicked()
{
    qDebug()<<"启动客户端";
    client* cli=new client();
    cli->setWindowTitle("客户端");
    cli->setWindowFlags(Qt::Window | Qt::WindowStaysOnTopHint);
    cli->show();
}


void MainWindow::on_btnStart3D_clicked()
{
    form3d* _my3d=new form3d();
    _my3d->show();
}


void MainWindow::on_btnStartCharts_clicked()
{
    FormCharts* charts=new FormCharts();
    charts->show();
}


void MainWindow::on_pushButton_2_clicked()
{
    QString filename= QFileDialog::getOpenFileName(this,tr("open images"),"c:/",tr("Image Files (*.png *.jpg *.bmp)"));
    qDebug()<<filename;
}

